import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Fortaleza3 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Fortaleza3 extends World
{
    private Grass grass1;
    private Grass grass2;
    private Grass grass3;
    private Grass grass4;
    private Monster mons1;
    private Monster mons2;
    private Monster mons3;
    private Monster mons4;
    private Heroe heroe;
    private Activador act2;
    private PuertaV puerta;
    private Counter monedas;
    private SimpleTimer timer2=new SimpleTimer();
    private int wave;

    public Fortaleza3()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1,false);   
        wave=3;
        prepare();
    }

    public void act()
    {
        play();
        endGame();
        win();
    }

    public void endGame()
    {
        if(act2.isDestroyed()==true || puerta.isDestroyed()==true)
        {
            heroe.actualizaPuntos();
            removeObjects( getObjects(Actor.class) );
            setBackground("game-over.jpg");
            Menu menu=new Menu();
            if(Greenfoot.isKeyDown("enter"))
                Greenfoot.setWorld(menu);
        }
    }

    public void win()
    {
        if(heroe.getGanas()&&puerta.getDisponible())
        {
            heroe.actualizaPuntos();
            removeObjects( getObjects(Actor.class) );
            setBackground("win.jpg");
            Menu menu=new Menu();
            if(Greenfoot.isKeyDown("enter"))
                Greenfoot.setWorld(menu);
        }
    }

    public void play()
    {
        switch(wave)
        {
            case 3:
            wave3();
            break;
        }
    }

    public void wave3()
    {
        if(timer2.millisElapsed()>=2000)
        {
            int x=Greenfoot.getRandomNumber(7);           
            if(x==0)
            {
                mons1=new Monster(grass1,20);
                addObject(mons1,222,600);    
            }
            if(x==2)
            {
                mons2=new Monster(grass2,20);
                addObject(mons2,0,295);
            }
            if(x==4)
            {
                mons3=new Monster(grass3,20);
                addObject(mons3,260,0);
            }
            if(x==6)
            {
                mons4=new Monster(grass4,20);
                addObject(mons4,580,0);
            }
            timer2.mark();
        }
    }

    public Heroe getHeroe()
    {
        return heroe;
    }

    public Activador getActivador()
    {
        return act2;
    }

    public PuertaV getPuerta()
    {
        return puerta;
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        grass1=new Grass();
        addObject(grass1,222,483);      
        grass2=new Grass();
        addObject(grass2,135,295);      
        grass3=new Grass();
        addObject(grass3,260,90);      
        grass4=new Grass();
        addObject(grass4,580,90);      
        heroe=new Heroe(100);
        addObject(heroe,32,422);
        Wall3 wall3 = new Wall3();
        addObject(wall3, 261, 172);
        Wall3 wall32 = new Wall3();
        addObject(wall32, 393, 127);
        Wall3 wall33 = new Wall3();
        addObject(wall33, 486, 247);
        Wall3 wall34 = new Wall3();
        addObject(wall34, 554, 158);
        Wall3 wall35 = new Wall3();
        addObject(wall35, 620, 235);
        Wall3 wall36 = new Wall3();
        addObject(wall36, 676, 330);
        Wall3 wall37 = new Wall3();
        addObject(wall37, 476, 362);
        Wall4 wall4 = new Wall4();
        addObject(wall4, 649, 118);
        Wall4 wall42 = new Wall4();
        addObject(wall42, 499, 86);
        Wall4 wall43 = new Wall4();
        addObject(wall43, 392, 105);
        Wall4 wall44 = new Wall4();
        addObject(wall44, 270, 103);
        Wall4 wall45 = new Wall4();
        addObject(wall45, 221, 133);
        Wall4 wall46 = new Wall4();
        addObject(wall46, 176, 174);
        Wall4 wall47 = new Wall4();
        addObject(wall47, 184, 259);
        Wall4 wall48 = new Wall4();
        addObject(wall48, 419, 334);
        Wall4 wall49 = new Wall4();
        addObject(wall49, 473, 296);
        Wall4 wall410 = new Wall4();
        addObject(wall410, 648, 305);
        wall48.setLocation(365, 246);
        wall37.setLocation(70, 500);
        wall33.setLocation(66, 358);
        wall36.setLocation(212, 499);
        wall34.setLocation(353, 499);
        wall32.setLocation(494, 498);
        wall47.setLocation(149, 299);
        wall410.setLocation(576, 439);
        wall49.setLocation(432, 156);
        wall35.setLocation(519, 354);
        wall48.setLocation(552, 160);
        wall3.setLocation(377, 355);
        wall49.setLocation(318, 274);
        wall46.setLocation(149, 161);
        wall4.setLocation(734, 408);
        wall48.setLocation(652, 392);
        wall42.setLocation(760, 382);
        wall43.setLocation(392, 105);
        wall43.setLocation(775, 478);
        wall44.setLocation(680, 444);
        wall45.setLocation(653, 380);
        Wall3 wall38 = new Wall3();
        addObject(wall38, 462, 264);
        Wall3 wall39 = new Wall3();
        addObject(wall39, 459, 229);
        Wall3 wall310 = new Wall3();
        addObject(wall310, 574, 229);
        wall38.setLocation(232, 100);
        wall39.setLocation(400, 214);
        wall310.setLocation(540, 214);
        removeObject(wall44);
        removeObject(wall48);
        removeObject(wall45);
        removeObject(wall4);
        removeObject(wall43);
        removeObject(wall42);
        Wall3 wall311 = new Wall3();
        addObject(wall311, 670, 340);
        Wall3 wall312 = new Wall3();
        addObject(wall312, 685, 361);
        Wall3 wall313 = new Wall3();
        addObject(wall313, 672, 297);
        wall313.setLocation(373, 99);
        wall312.setLocation(513, 99);
        wall311.setLocation(680, 213);
        Wall3 wall314 = new Wall3();
        addObject(wall314, 662, 105);
        wall314.setLocation(654, 99);
        Wall3 wall315 = new Wall3();
        addObject(wall315, 733, 104);
        wall315.setLocation(732, 100);
        Wall3 wall316 = new Wall3();
        addObject(wall316, 734, 219);
        wall316.setLocation(736, 213);
        wall316.setLocation(404, 150);
        wall315.setLocation(676, 34);
        Wall4 wall411 = new Wall4();
        addObject(wall411, 661, 323);
        wall311.setLocation(353, 162);
        wall316.setLocation(577, 213);
        wall411.setLocation(638, 299);
        Wall4 wall412 = new Wall4();
        addObject(wall412, 743, 164);
        wall412.setLocation(735, 157);
        Wall4 wall413 = new Wall4();
        addObject(wall413, 516, 269);
        Wall4 wall414 = new Wall4();
        addObject(wall414, 433, 231);
        Wall4 wall415 = new Wall4();
        addObject(wall415, 527, 186);
        Wall4 wall416 = new Wall4();
        addObject(wall416, 586, 187);
        Wall4 wall417 = new Wall4();
        addObject(wall417, 610, 174);
        wall417.setLocation(735, 298);
        wall416.setLocation(637, 441);
        wall415.setLocation(735, 435);
        wall413.setLocation(637, 555);
        wall414.setLocation(433, 231);
        wall414.setLocation(433, 231);
        wall414.setLocation(433, 231);
        wall414.setLocation(433, 231);
        wall414.setLocation(735, 553);
        wall413.setLocation(637, 511);
        wall414.setLocation(734, 500);
        wall413.setLocation(637, 498);
        wall414.setLocation(735, 500);
        wall311.setLocation(531, 41);
        removeObject(wall311);
        removeObject(wall315);
        wall36.setLocation(116, 500);
        wall46.setLocation(254, 280);
        Wall2 wall2 = new Wall2();
        addObject(wall2, 194, 149);
        removeObject(wall2);
        Wall3 wall317 = new Wall3();
        addObject(wall317, 217, 106);
        wall317.setLocation(211, 99);
        wall314.setLocation(576, 99);
        wall46.setLocation(18, 166);
        wall411.setLocation(659, 39);
        Wall3 wall318 = new Wall3();
        addObject(wall318, 577, 252);
        removeObject(wall416);
        removeObject(wall413);
        removeObject(wall414);
        removeObject(wall415);
        removeObject(wall417);
        wall412.setLocation(754, 473);
        wall318.setLocation(718, 213);
        wall412.setLocation(773, 133);
        wall46.setLocation(772, 70);
        wall318.setLocation(478, 250);
        Wall4 wall418 = new Wall4();
        addObject(wall418, 780, 160);
        wall418.setLocation(774, 152);
        wall310.setLocation(494, 214);
        wall418.setLocation(728, 395);
        wall318.setLocation(524, 257);
        wall318.setLocation(716, 213);
        Wall3 wall319 = new Wall3();
        addObject(wall319, 81, 104);
        wall319.setLocation(78, 97);
        Wall3 wall320 = new Wall3();
        addObject(wall320, 78, 244);
        wall320.setLocation(67, 239);
        wall319.setLocation(69, 99);
        wall412.setLocation(680, 465);
        wall46.setLocation(678, 529);
        wall418.setLocation(659, 404);
        wall318.setLocation(743, 459);
        wall411.setLocation(656, 157);
        wall411.setLocation(671, 299);
        wall318.setLocation(714, 99);
        wall411.setLocation(771, 164);
        wall418.setLocation(659, 272);
        wall412.setLocation(771, 305);
        Wall3 wall321 = new Wall3();
        addObject(wall321, 720, 394);
        wall321.setLocation(714, 385);
        wall46.setLocation(659, 304);
        wall321.setLocation(717, 385);
        BoxWeapon boxweapon = new BoxWeapon();
        addObject(boxweapon, 726, 341);
        boxweapon.setLocation(719, 329);
        wall314.setLocation(563, 283);
        wall312.setLocation(481, 100);
        wall47.setLocation(194, 254);
        wall47.setLocation(744, 515);
        wall317.setLocation(210, 41);
        wall38.setLocation(298, 31);
        wall317.setLocation(126, 98);
        wall411.setLocation(642, 423);
        wall411.setLocation(771, 167);
        removeObject(wall47);
        wall313.setLocation(476, 58);
        wall312.setLocation(367, 90);
        wall312.setLocation(394, 95);
        wall312.setLocation(385, 95);
        wall313.setLocation(453, 96);
        wall313.setLocation(455, 94);
        wall310.setLocation(489, 213);
        removeObject(wall314);
        wall317.setLocation(129, 100);
        wall317.setLocation(133, 95);
        wall319.setLocation(68, 96);
        removeObject(wall38);
        removeObject(boxweapon);
        wall36.setLocation(678, 494);
        wall37.setLocation(71, 497);
        wall34.setLocation(356, 498);
        wall34.setLocation(360, 497);
        wall34.setLocation(362, 498);
        wall317.setLocation(117, 97);
        wall313.setLocation(422, 137);
        wall312.setLocation(401, 95);
        wall319.setLocation(66, 93);
        wall317.setLocation(117, 93);
        wall313.setLocation(430, 95);
        wall317.setLocation(120, 95);
        wall319.setLocation(61, 94);
        wall317.setLocation(116, 97);
        wall319.setLocation(60, 97);
        wall318.setLocation(714, 82);
        wall313.setLocation(433, 95);
        wall318.setLocation(715, 95);
        removeObject(wall36);
        act2 = new Activador();
        addObject(act2, 516, 432);
        puerta = new PuertaV(act2);
        addObject(puerta, 18, 168);        
        Wall4 wall419 = new Wall4();
        addObject(wall419, 497, 18);
        wall419.setLocation(490, 13);
    }
}